#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[55][55];
int dp[55][55][2];
bool check() {
  rep(i, 1, n) rep(j, 1, m) {
    if (!a[i][j])
      dp[i][j][0] = dp[i][j][1] = 0;
    else {
      dp[i][j][1] = dp[i - 1][j][1];
      dp[i][j][0] = dp[i][j - 1][0];
      if (!dp[i][j][0] && !dp[i][j][1]) return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  rep(i, 1, 54) dp[0][i][1] = dp[i][0][0] = 1;
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    rep(i, 1, n) rep(j, 1, m) {
      char c;
      cin >> c;
      a[i][j] = c - '0';
    }
    cout << (check() ? "YES\n" : "NO\n");
  }
  return 0;
}